<?

class Inktype_System {

	// This library is mainly used to provide a route for model to model communication where required

	var $CI;

	function Inktype_System() {

		$this->CI =& get_instance();

	}

	function auth() {

		return $this->CI->mdl_users->auth();

	}

	function clean_orphans() {

		$this->CI->db->query('DELETE FROM inktype_posts WHERE site_id NOT IN (SELECT site_id FROM inktype_sites)');

		$this->CI->db->query('DELETE FROM inktype_pages WHERE site_id NOT IN (SELECT site_id FROM inktype_sites)');

		$this->CI->db->query('DELETE FROM inktype_users WHERE site_id NOT IN (SELECT site_id FROM inktype_sites)');

		$this->CI->db->query('DELETE FROM inktype_user_meta WHERE user_id NOT IN (SELECT user_id FROM inktype_users)');

		$this->CI->db->query('DELETE FROM inktype_postcats WHERE post_id NOT IN (SELECT post_id FROM inktype_posts)');

	}

	function current_site_url($site_id) {

		return site_url($this->CI->mdl_sites->get(array('site_id'=>$site_id, 'select'=>'url_title'))->url_title);

	}

	function mdl_session_refresh($user_id) {

		$this->CI->mdl_sessions->refresh($user_id);

	}

	function user_is_global() {

		if ($this->CI->mdl_user_types->is_global()) {

			return TRUE;

		}

		return FALSE;

	}

	function user_is_admin() {

		if ($this->CI->mdl_user_types->is_admin($this->CI->session->userdata('user_type_id'))) {

			return TRUE;

		}

		else {

			return FALSE;

		}

	}

}

?>